import instance from "@/utils/request";

// 用户登录验证
export const userLoginService = (data) => {
  return instance({
    url: "/api/login",
    method: "post",
    headers: {
      "Content-Type": "application/json",
    },
    data,
  }).then((res) => res.data);
};

// 用户注册
export const userRegisterService = (data) => {
  return instance({
    url: "/api/register",
    method: "post",
    headers: {
      "Content-Type": "application/json",
    },
    data,
  }).then((res) => res.data);
};

// 获取用户信息
export const getUserInfoService = () => {
  return instance({
    url: "/api/user",
    method: "get",
  }).then((res) => res.data);
};

// 修改个人信息
export const updateUserInfoService = (data) => {
  return instance({
    url: "/api/user",
    method: "put",
    headers: {
      "Content-Type": "application/json",
    },
    data,
  }).then((res) => res.data);
};

// 查询个人的关注列表
export const getUserFollowListService = () => {
  return instance({
    url: `/api/user/getFollowed`,
    method: "get",
  }).then((res) => res.data);
};

//删除关注
export const deleteUserFollowService = (id) => {
  return instance({
    url: `/api/user/deleteFollow/${id}`,
    method: "delete",
  }).then((res) => res.data);
};

//根据id和页码和每页数量获取用户发布的话题
export const getUserTopicsService = (id, pageNum, pageSize) => {
  return instance({
    url: `/api/user/getUserPublishTopic/`,
    method: "POST",
    data: {
      id,
      topicPageNum: pageNum,
      topicPageSize: pageSize,
    },
  }).then((res) => res.data);
};

// 获取用户点赞的话题列表
export const getUserLikedTopicsService = () => {
  return instance({
    url: `/api/user/getUserLikeTopic`,
    method: "get",
  }).then((res) => res.data);
};

// 根据id获取用户的发言
export const getUserSpeechesService = (id) => {
  return instance({
    url: `/api/user/getUserSpeeches/${id}`,
    method: "get",
  }).then((res) => res.data);
};
